<extend name="public:base"/>

<block name="css">
    <link rel="stylesheet" href="__CSS__/member.css?v={:config('app_ver')}"/>
    <link rel="stylesheet" href="__CSS__/sign.css?v={:config('app_ver')}"/>
    <style>
        .inputWrapper.add_bankcard {
            padding-top: 10px;
        }

        .inputWrapper.add_bankcard td:last-child {
            padding: 0;
        }

        .inputWrapper.add_bankcard td:first-child {
            padding: 0 20px 0 0;
        }
    </style>
</block>

<block name="main">

    <div class="slide_main fr">
        <h1 class="frame_title mb10">收货地址</h1>
        <div class="frame_slide" id="rotate">

            <include file="safe:menu"/>

        </div>
        <div class="frame_slide_con bd">
            <div class="registerStep noPadding">


                <notempty name="address">

                    <div class="frame_slide_con">

                        <!-- 充值记录 -->
                        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tableBlue">
                            <tr class="first">
                                <th class="first">编号</th>
                                <th>收货人姓名</th>
                                <th>收货人手机号</th>
                                <th>收货地址</th>
                                <th class="last">操作</th>
                            </tr>

                            <notempty name="address">
                                <volist name="address" id="v">
                                    <tr>
                                        <td class="first">{$i}</td>
                                        <td>{$v.name}</td>
                                        <td>{$v.phone}</td>
                                        <td>{$v.address}</td>
                                        <td class="last">
                                            <a href="{:url('del_address')}?id={$v.id}">删除</a>
                                        </td>
                                    </tr>
                                </volist>

                                <else/>

                                <td colspan="100" class="text-center"> 暂无内容</td>
                            </notempty>
                        </table>
                        <div class="page">
                            {$page|default=''}
                        </div>

                    </div>

                    <else/>

                    <!-- 修改密码 -->
                    <form action="{:url('user/safe/add_ress')}" method="post" id="editAddressForm">
                        <div class="inputWrapper add_bankcard" style="width: 100%;">
                            <table width="100%">
                                <tr>
                                    <td class="a666" width="100px" style="line-height: 44px;" valign="top"
                                        align="right">收货人姓名
                                    </td>
                                    <td>
                                        <div class="inputBox">
                                            <input type="text" name="name" maxlength="20" value="" class="input"
                                                   id="name" placeholder="真实全名" required/>
                                            <div class="inputTip"><i class="iconFont">&#xe62a;</i><span></span></div>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="a666" style="line-height: 44px;" valign="top" align="right">收货人手机号</td>
                                    <td>
                                        <div class="inputBox">
                                            <input type="number" name="phone" min="0" maxlength="11" value=""
                                                   class="input" id="phone" placeholder="请输入11位大陆手机号" required/>
                                            <div class="inputTip"><i class="iconFont">&#xe62a;</i><span></span></div>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="a666" style="line-height: 44px;" valign="top" align="right">收货人地址</td>
                                    <td>
                                        <div class="inputBox">
                                            <input type="text" name="address" value="" maxlength="200" class="input"
                                                   id="address" placeholder="请输入地址，精确到门牌号码" required/>
                                            <div class="inputTip"><i class="iconFont">&#xe62a;</i><span></span></div>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>&nbsp;</td>
                                    <td>
                                        <div class="submitLine">
                                            <p class="mb20 mt10">
                                                <input type="hidden" name="id" value="0">
                                                <input type="submit" value="确认添加" class="btn_b" id="inputSubmit"/>
                                            </p>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </div>

                    </form>

                </notempty>


            </div>
        </div>
    </div>

</block>

<block name="js">

    <script type="text/javascript" src="__JS__/sign.js?v={:config('app_ver')}"></script>
    <script type="text/javascript">
        $(function () {

            /**
             * TODO：AJAX提交，disable按钮和增加样式
             */
            // $(document).ajaxStart(function () {
            //     $('#inputSubmit').addClass("disabled").attr("disabled", true).val('正在提交');
            // }).ajaxStop(function () {
            //     $('#inputSubmit').removeClass("disabled").attr("disabled", false).val('立即修改');
            // });

            // $("#pwd0").blur(function () {
            //
            //     setPassword0();
            //     var newval = $("#pwd1").val();
            //     if(newval !== "" || newval.length > 0){
            //         if(checkPassword0()){
            //             $("#pwd1").removeClass("on")
            //                 .siblings(".inputTip")
            //                 .css("visibility","hidden").find("span").html("");
            //         }
            //     }
            // });
            //
            // $("#pwd1").blur(function () {
            //     setPassword0();
            //     setPassword1();
            //     checkPassword0();
            // });
            //
            // $("#pwd2").blur(function () {
            //     setPassword0();
            //     setPassword1();
            //     setPassword2();
            // });

            /**
             * TODO:AJAX 提交表单
             */
            $("#editAddressForm").submit(function () {

                var self = $(this);

                $.post(self.attr("action"), self.serialize(), success, "json");
                return false;

                function success(data) {
                    if (data.code === 1) {
                        layer.alert(data.msg, {icon: 1}, function (index) {
                            if (data.data || data.url) {
                                var refer = data.data || data.url;
                                layer.close(index);
                                window.location.href = refer;
                                setTimeout(function () {
                                    window.location.href = refer;
                                }, 2000);
                            } else {
                                window.location.reload();
                            }
                        });
                    } else {
                        if (data.msg !== '') {
                            layer.alert(data.msg, {icon: 2});
                        } else {
                            checkErrorType(data);
                        }
                    }
                }
            });


        });
    </script>

</block>

